import { UaIpEntity } from "../models/ua-ip.model";
import { GlobalService } from "./global.service";


export class UaIpService {
  static PATH = "/ua/ip";
  static fetchUaIpList() {
    console.log(`${GlobalService.HOST}${UaIpService.PATH}`);
    return new Promise<UaIpEntity[]>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}${UaIpService.PATH}`,
          method: "GET",
          success: (response) => resolve(response.data as UaIpEntity[]),
          fail: (err) => reject(err)
        });
      }
    )
  }

  static fetchUaIp(ipId: number) {
    return new Promise<UaIpEntity>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}${UaIpService.PATH}/${ipId}`,
          method: "GET",
          success: (response) => resolve(response.data as UaIpEntity),
          fail: (err) => reject(err)
        });
      }
    )
  }
}
